package com.purchase.ml.utils;

import com.purchase.ml.consts.CommonConsts;
import com.purchase.ml.entity.acc.SysUser;
import com.purchase.ml.entity.prod.SysProduct;
import com.purchase.ml.entity.prod.SysProductSku;
import com.purchase.ml.security.JwtUtil;

import java.math.BigDecimal;

/**
 * Created by kyyang on 2021/2/28 13:51
 */
public class ShoppingCartUtils {

    //获取当前用户购物车key
    public static String getCurShoppingCartKey(){
        SysUser currentUser = JwtUtil.getCurrentUser();
        String str = MD5.md5(currentUser.getAcc(), currentUser.getSalt());
        return CommonConsts.SHOPPING_CART_KEY+str;
    }

    public static BigDecimal getProductTotalMoney(SysProduct sysProduct,int qty,int dealerType){
        BigDecimal price = BigDecimal.ZERO;
        if(dealerType == CommonConsts.ROLETYPE_MASTER ){
            price = sysProduct.getPriceMasterDealer();
        }
        if(dealerType == CommonConsts.ROLETYPE_DEALER ){
            price = sysProduct.getPriceDealer();
        }

        return price.multiply(BigDecimal.valueOf(qty));
    }


}
